'GetLastError return the code number of the error when the systray access fail
Private Declare Function GetLastError Lib "kernel32" () As Long
'Shell_NotifyIcon is THE function to add, modify or delete an existing icon.
'If it return 'True', that mean that the call was successful.
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
'Arguments of 'Shell_NotifyIcon':
'dwMessage: double word message. This represent the action
'to execute on the Systray. The message can be one of
'the following constants:
Private Const NIM_ADD = &H0 'Add a new icon to the Systray
Private Const NIM_MODIFY = &H1 'Modify an existing icon
Private Const NIM_DELETE = &H2 'Delete an existing icon
'pnid: pointer to a NOTIFYICONDATA type (see below)
'This represent the info on the icon.
'Constants for the member 'uFlag' of the NOTIFYICONDATA type
'uFlag can be a combinaison of these three constants
Private Const NIF_MESSAGE = &H1 'Tell that the message has been updated
Private Const NIF_ICON = &H2 'Tell that the icon picture has been changed
Private Const NIF_TIP = &H4 'Tell that a new ToopTip for the icon is set
Private Const WM_MOUSEMOVE = &H200 'Used as the ID of the callback message
Private Const MAX_TIP_LENGTH As Long = 64 'This is the max length
'of a ToolTip. This value has been tested for Win95.
'For Win98 and NT, try changing this value. Tell me
'if it is a different value.
Private Type NOTIFYICONDATA
cbSize As Long 'The size of this type
hWnd As Long 'The hWnd that will receive the CallBack message
uId As Long 'The ID of the application. Zero represent this application
uFlags As Long 'The flags. Look at the constants beginning by NIF_ for the flags and their definition
uCallbackMessage As Long 'This is the callback message
hIcon As Long 'An handle to the icon that will be displayed
szTip As String * MAX_TIP_LENGTH 'The string of the ToopTip. Must be terminating by a null zero (chr(0))
End Type
'The variable that will be used to interfere with the Systray
Private nidTrayIcon As NOTIFYICONDATA
Private bIconDisplayed As Boolean 'The status of the icon. True=Displayed
Private bUpdateOnChange As Boolean 'If True, Shell_NotifyIcon is call
'whenever a change to a properties
'of nidTrayIcon is made
'True when class is initialized.
Public Event NIError(ByVal ErrorNumber As Long)
Public PopUpMessage As String
'Now for the Class Members
Public Function Initialize(ByVal hWnd As Long, ByVal hIcon As Long, ByVal sTip As String, Optional ByVal uCallbackMessage As Long = WM_MOUSEMOVE) As Long
'Initialize the systray icon (The icon won't show)
'THIS FUNCTION MUST BE THE FIRST MEMBER TO BE CALL AFTER
'CREATING A INSTANCE OF THIS CLASS
'
'Input: hWnd: Handle of the window that receives notification
' messages associated with an icon in the taskbar
' status area.
' hIcon: Handle of the icon to add, modify, or delete.
' This is not directly the bitmap. It is his handle
' in memory. So instead of using Picture1.Picture,
' you can use LoadPicture() or LoadResPicture() if